<?php

namespace Addons\Draw\Model;

use Think\Model;

/**
 * Award奖品库模型
 */
class AwardModel extends Model
{
    protected $tableName = 'sport_award';

    function getInfo($id, $update = false, $data = array())
    {
        $key = 'Award_getInfo_' . $id;
        $info = S($key);
        if ($info === false || $update) {
            $info = ( array )(empty ($data) ? $this->find($id) : $data);
            if (count($info) != 0) {
                if ($info['award_type'] == 0) {
                    $info['price'] = $info['score'] . '积分';
                } else {
                    $info['price'] = $info['price'] == 0 ? '未报价' : $info['price'];
                }
            }
            S($key, $info, 86400);
        }
        return $info;
    }

    function update($id, $data = array())
    {
        $map['id'] = $id;
        $res = $this->where($map)->save($data);
        if ($res) {
            $this->clear($id);
        }
        return $res;
    }

    function clear($id)
    {
        $this->getInfo($id, true);
    }
}
